<template>
  <div>
    <el-form ref="form" :model="form" label-width="150px">
      <el-form-item label="商品分类">
        <el-cascader clearable change-on-select v-model="form.cate_ids" :options="tree" :props="defaultProps" :show-all-levels="false"></el-cascader>
      </el-form-item>
      <el-form-item label="人民币改变倍数" prop="fund">
        <el-input class="w200" v-model="form.multiple" placeholder="默认倍数为1，即不改价"></el-input>
        <span style="margin-left: 20px; color: #999999">默认倍数为1，即不改价</span>
      </el-form-item>
      <!--<el-form-item label="亚数币改变倍数" prop="integral">-->
        <!--<el-input class="w200" v-model="form.currency_multiple" placeholder="默认倍数为1，即不改价"></el-input>-->
        <!--<span style="margin-left: 20px; color: #999999">默认倍数为1，即不改价</span>-->
      <!--</el-form-item>-->
      <el-form-item>
        <el-button type="primary" @click="onSubmit('form')">提交</el-button>
        <el-button @click="goBack">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import {mapState} from 'vuex'
  import notify from '@/tools/notify'

  export default {
    data: function () {
      return {
        defaultProps: {
          value: 'id',
          label: 'name',
          children: '_child'
        },
        form: {
          cate_ids: [],
          multiple: 1,
          currency_multiple: 1
        },
        submit: {
          cate_id: 0,
          multiple: 1,
          currency_multiple: 1
        }
      }
    },
    computed: {
      ...mapState({
        tree: state => state.goodsclass.goodsTree
      })
    },
    created () {
      this.goodsClassTree()
    },
    methods: {
      // 获取商品分类树
      async goodsClassTree () {
        let payload = {
          id: 0
        }
        await this.$store.dispatch('goodsclass/goodsClassTree', payload)
      },
      onSubmit (formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.submit.cate_id = this.form.cate_ids[this.form.cate_ids.length - 1]
            this.submit.multiple = this.form.multiple
            this.submit.currency_multiple = this.form.currency_multiple
            this.$store.dispatch('goods/batchChangePrice', this.submit).then(res => {
              notify.success(res.msg)
              this.$router.push('/goods/yhgoods')
            })
          }
        })
      },
      goBack () {
        this.$router.go(-1)
      }
    }
  }
</script>

<style scoped>
  .w200 {
    width: 200px;
  }
</style>
